﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">Using Unity as primary IoC container</title>
  <keywords>
    <keyword translate="true">Inversion of Control</keyword>
    <keyword translate="true">IoC</keyword>
    <keyword translate="true">Unity</keyword>
  </keywords>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Using Unity as primary IoC container</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">If you are going for Catel, we always recommend to use the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_IoC_ServiceLocator" styleclass="Normal" translate="true">ServiceLocator</link><text styleclass="Normal" translate="true"> of Catel as primary IoC container. However, if you want to use Unity as the primary IoC container, follow the instructions below.</text></para>
    <para styleclass="Notes"><text styleclass="Notes" translate="true">This is not a full starting guide to Unity, if you are looking for documentation about Unity, continue searching</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Registering the container in Catel</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">It is required to register the external container in the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_IoC_ServiceLocator" styleclass="Normal" translate="true">ServiceLocator</link><text styleclass="Normal" translate="true"> of Catel. This is required because all the items that are registered by Catel itself are known in the Unity container. Catel will automatically register all types in the Unity container when the container is registered.To register the container, simple use this call when the container is created:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">ServiceLocator.Instance.RegisterExternalContainer(myUnityContainer);</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">At this point, all the services registered by Catel are now registered in the Unity container.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Resolving properties</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">In Unity, it is required to resolve properties like this:</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">PleaseWaitService = myUnityContainer.Resolve&lt;IPleaseWaitService&gt;();</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The code above imports the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_MVVM_Services_IPleaseWaitService" styleclass="Normal" translate="true">IPleaseWaitService</link><text styleclass="Normal" translate="true"> (which is internally registered by Catel) via Unity.</text></para>
  </body>
</topic>
